package com.osfw.system.entity.manage;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.osfw.framework.core.entity.BaseEntity;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.List;

/**
 * 菜单权限表 sys_menu
 */
@Data
@Accessors(chain = true)
public class SysMenu extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /* 菜单ID */
    @TableId(value = "menu_id_", type = IdType.ASSIGN_ID)
    private Long menuId;

    /* 菜单名称 */
    @NotBlank(message = "菜单名称不能为空")
    @Size(min = 0, max = 50, message = "菜单名称长度不能超过50个字符")
    @TableField(value = "menu_name_")
    private String menuName;

    /* 父菜单名称 */
    @TableField(exist = false)
    private String parentName;

    /* 父菜单ID */
    @TableField(value = "parent_id_")
    private Long parentId;

    /* 显示顺序 */
    @NotNull(message = "显示顺序不能为空")
    @TableField(value = "order_num_")
    private Integer orderNum;

    /* 菜单URL */
    @Size(min = 0, max = 500, message = "请求地址不能超过500个字符")
    @TableField(value = "url_")
    private String url;

    /* 打开方式（menuItem页签 menuBlank新窗口） */
    @TableField(value = "target_")
    private String target;

    /* 类型（M目录 C菜单 F按钮） */
    @NotBlank(message = "菜单类型不能为空")
    @TableField(value = "menu_type_")
    private String menuType;

    /* 菜单状态（0显示 1隐藏） */
    @TableField(value = "visible_")
    private String visible;

    /* 权限字符串 */
    @Size(min = 0, max = 100, message = "权限标识长度不能超过100个字符")
    @TableField(value = "perms_")
    private String perms;

    /* 菜单图标 */
    @TableField(value = "icon_")
    private String icon;

    /* 系统背景 */
    @TableField(value = "background_")
    private String background;

    /* 是否父节点（0否 1是） */
    @TableField(value = "is_parent_")
    private String isParent;

    /* 是否系统内置（Y是 N否） */
    @TableField(value = "build_in_")
    private String buildIn;

    /* 子菜单 */
    @TableField(exist = false)
    private List<SysMenu> children = new ArrayList<SysMenu>();


    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("menuId", getMenuId())
                .append("menuName", getMenuName())
                .append("parentId", getParentId())
                .append("orderNum", getOrderNum())
                .append("url", getUrl())
                .append("target", getTarget())
                .append("menuType", getMenuType())
                .append("visible", getVisible())
                .append("perms", getPerms())
                .append("icon", getIcon())
                .append("isParent", getIsParent())
                .append("createBy", getCreateBy())
                .append("createTime", getCreateTime())
                .append("updateBy", getUpdateBy())
                .append("updateTime", getUpdateTime())
                .append("remark", getRemark())
                .toString();
    }
}
